package com.cwvs.controller.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cwvs.services.AppAdvertService;
import com.cwvs.services.AppAreaService;
import com.cwvs.services.AppDepartmentService;
import com.cwvs.services.AppOrderService;
import com.cwvs.services.AppStoreService;
import com.cwvs.utils.Pages;

@Controller
@RequestMapping("/api")
public class PublicController {
	@Resource
	private AppAdvertService appAdvertService;
	@Resource
	private AppAreaService appAreaService;
	@Resource
	private AppStoreService appStoreService;
	@Resource
	private AppDepartmentService appDepartmentService;
	@Resource
	private AppOrderService appOrderService;

	/**
	 * 首页广告位
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/advert_list")
	public @ResponseBody
	List<Map<String, Object>> advertList(HttpServletRequest request,
			HttpServletResponse response) {
		return appAdvertService.advertList();
	}

	/**
	 * 地区列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/area_list")
	public @ResponseBody
	List<Map<String, Object>> areaList(HttpServletRequest request,
			HttpServletResponse response) {
		String parentId = request.getParameter("pid");
		return appAreaService.areaList(parentId);
	}
	/**
	 * 店铺列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/store_list")
	public @ResponseBody
	List<Map<String, Object>> storeList(HttpServletRequest request,
			HttpServletResponse response) {
//		String provinceId = request.getParameter("province_id");
//		String cityId = request.getParameter("city_id");
//		String countyId = request.getParameter("county_id");
//		String streetId = request.getParameter("street_id");
//		String type=request.getParameter("type");
//		String outType=request.getParameter("out_type");
		Pages page = new Pages();
		page.setCurrentPage(StringUtils.isBlank(request.getParameter("page"))?1:Integer.parseInt(request.getParameter("page")));
		HashMap<String, Object> paramsMap = new HashMap<String, Object>();
		String province_id=request.getParameter("province_id");
		String city_id=request.getParameter("city_id");
		String county_id=request.getParameter("county_id");
		String street_id=request.getParameter("street_id");
		paramsMap.put("PROVINCE_ID", province_id);
		paramsMap.put("CITY_ID", city_id);
		paramsMap.put("COUNTY_ID", county_id);
		paramsMap.put("STREET_ID", street_id);
		String store_type=request.getParameter("type");
		if(StringUtils.equalsIgnoreCase("-1", store_type)){
			store_type="";
		}
		paramsMap.put("STORE_TYPE", store_type);
		paramsMap.put("CODE", request.getParameter("code"));
		paramsMap.put("NAME", request.getParameter("name"));
		page=appStoreService.storeList(paramsMap, page);
		return (List<Map<String, Object>>) page.getPage();
	}
	/**
	 * 店铺列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/store_info")
	public @ResponseBody
	Map<String, Object> getOrderInfoById(HttpServletRequest request,
			HttpServletResponse response) {
		return appStoreService.getStoreInfoById(request.getParameter("id"));
	}
	
	
	/**
	 * 外卖类型列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/out_type")
	public @ResponseBody
	List<Map<String, Object>> outTypeList(HttpServletRequest request,
			HttpServletResponse response) {
		return appStoreService.outTypeList();
	}
	
	/**
	 * 通过店铺ID获取科室列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/department_list")
	public @ResponseBody
	List<Map<String, Object>> departmentList(HttpServletRequest request,
			HttpServletResponse response) {
		return appDepartmentService.departmentList(request.getParameter("store_id"));
	}
	/**
	 * 通过科室ID获取专家列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/person_list")
	public @ResponseBody
	List<Map<String, Object>> personList(HttpServletRequest request,
			HttpServletResponse response) {
		return appDepartmentService.personList(request.getParameter("department_id"));
	}
	/**
	 * 外卖类型列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/car_type")
	public @ResponseBody
	List<Map<String, Object>> carType(HttpServletRequest request,
			HttpServletResponse response) {
		return appOrderService.getCarType();
	}
}
